package com.weilive.api.dao.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.weilive.api.dao.model.UserInfo;
import com.weilive.api.dao.model.UserSalary;

public interface UserMapper {
	
	//final String SQL_COLUMN = "user_id, user_pass, user_account, user_alias, user_type_id, user_pic,e_money, e_money_used, gift_coin, red_cnt, got_red_cnt, profile_pic,updated_time, vip_expiration, vj_type_id, vj_subtype_id,room_pic,user_msg, gift_num,user_system_id, account_type";
	
	@Select("select user_id, user_pass, user_account, user_alias, user_type_id, user_pic,e_money, e_money_used, gift_coin, red_cnt, got_red_cnt, profile_pic,updated_time, vip_expiration, vj_type_id, vj_subtype_id,room_pic,user_msg, gift_num,user_system_id, account_type from user_info where user_id = #{userId}")
	@ResultMap("com.weilive.api.dao.mapper.UserMapper.UserInfoMap")
	UserInfo getUserInfo(@Param("userId") long userId);
	
	@Select("select user_id, user_alias, user_pic, vip_expiration from user_info where FIND_IN_SET (user_id, #{userIds})")
	@ResultMap("com.weilive.api.dao.mapper.UserMapper.UserInfoMap")
	List<UserInfo> getUserInfoList(@Param("userIds") String userIds);
	
	@Update("update user_info set profile_pic = #{profilePic}, user_alias = #{userAlias}, user_pic = #{userPic}  where user_id = #{userId}")
	public int setUserInfo(@Param("userId") long userId, @Param("profilePic") String profilePic, @Param("userAlias") String userAlias, @Param("userPic") String userPic);

	UserInfo selectByPrimaryKey(Long userId);

	int updateByPrimaryKeySelective(UserInfo record);

//	@Select("select "+ SQL_COLUMN + " from user_info where vj_type_id = #{vjTypeId} limit #{start} , #{maxCount}")
//	@ResultMap("com.weilive.api.dao.mapper.UserMapper.UserInfoMap")
//	List<UserInfo> findUserList(@Param("vjTypeId") int vjTypeId, @Param("start") int start, @Param("maxCount") int maxCount);
	
	@Select("select from_user_id, sum(gift_num) as price from tx_user_gift where to_user_id = #{userId} group by from_user_id order by price desc limit #{start} , #{maxCount}")
	@Results(value = { @Result(property = "userId", column = "from_user_id"),@Result(property = "price", column = "price") })
	List<UserSalary> findUserSalary(@Param("userId") long userId,@Param("start") int start, @Param("maxCount") int maxCount);
	
	@Delete("delete from user_vdo where id = #{id}")
	int deleteVideo(@Param("id") long id);
	
	
	@Select("select user_alias from user_info where user_alias = #{userAlias} limit 1")
	String getUserAlias(@Param("userAlias") String userAlias);
}
